/*
 * $Id: avatar.h 315 2010-03-25 23:57:03Z cmtonkinson@gmail.com $
 *
 * This file is part of the Symphony project <http://code.google.com/p/symphonymud/>
 * Copyright 2005-2010 Chris Tonkinson <cmtonkinson@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef H_SYMPHONY_AVATAR
#define H_SYMPHONY_AVATAR

#include <string>
#include "color-string.h"
#include "creature.h"
#include "socket.h"

// Administrative bits...
#define ADMIN_BIGBRO          A
#define ADMIN_BIGBRO_LOGINS   B
#define ADMIN_BIGBRO_MODES    C
#define ADMIN_BIGBRO_DEATHS   D

#define ADMIN_BIGBRO_EVENTS   E
#define ADMIN_BIGBRO_SYSTEM   F
#define ADMIN_BIGBRO_CHANGES  G
#define ADMIN_BIGBRO_ERRORS   H

#define ADMIN_BIGBRO_RESETS   I

#define ADMIN_INVIS           M
#define ADMIN_HEAD_BUILDER    N

// "Who" flags...
#define WHO_UNDEFINED 0
#define WHO_AFK       A
#define WHO_BUSY      B
#define WHO_BORED     C
#define WHO_DUNCE     D

// Channels...
#define CHAN_OOC      A
#define CHAN_TELL     B

class Area;
class Object;
class ObjContainer;
class Handler;
class Note;

class Avatar: public Creature {
  public:
    // constructors...
    Avatar( Socket* socket = NULL );
    virtual ~Avatar( void );

    // constants...
    enum Composing { Composing_Nothing = 0, Composing_Note };

    // public accessors...
    void                    socket( Socket* socket )                                  { _socket = socket; }
    Socket*                 socket( void )                                            { return _socket; }
    void                    output( const std::string& output )                       { _output = output; }
    ColorString             output( void ) const                                      { return _output; }
    void                    status( const unsigned short& status )                    { _status = status; }
    unsigned short          status( void )                                            { return _status; }

    // Overloads of pure virtual methods...
    virtual bool            save( void );
    virtual bool            load( void );
    virtual bool            destroy( void );

    // Overloads of virtual methods...
    virtual void            send( const std::string& message );
    virtual void            send( const char* format, ... );
    virtual void            disconnected( const bool& disconnected )                  { _disconnected = disconnected; }
    virtual bool            disconnected( void ) const                                { return _disconnected; }
    virtual void            adminFlags( const unsigned long& adminFlags )             { _adminFlags = adminFlags; }
    virtual unsigned long   adminFlags( void ) const                                  { return _adminFlags; }
    virtual void            admin( const unsigned long& flag, const bool& value )     { adminFlags( value ? (adminFlags()|flag) : (adminFlags()&(~flag)) ); }
    virtual bool            admin( const unsigned long& flag ) const                  { return ( ( adminFlags() & flag ) == flag ); }
    virtual void            gechoColor( const char& gechoColor )                      { _gechoColor = gechoColor; }
    virtual char            gechoColor( void ) const                                  { return _gechoColor; }
    virtual void            replyTo( const std::string& replyTo )                     { _replyTo = replyTo; }
    virtual std::string     replyTo( void )                                           { return _replyTo; }
    virtual void            channelFlags( const unsigned long& channelFlags )         { _channelFlags = channelFlags; }
    virtual unsigned long   channelFlags( void ) const                                { return _channelFlags; }
    virtual void            channel( const unsigned long& flag, const bool& value )   { channelFlags( value ? (channelFlags()|flag) : (channelFlags()&(~flag)) ); }
    virtual bool            channel( const unsigned long& flag ) const                { return ( ( channelFlags() & flag ) == flag ); }
    virtual void            composing( const Composing& composing )                   { _composing = composing; }
    virtual Composing       composing( void ) const                                   { return _composing; }
    virtual void            whoFlags( const unsigned long& whoFlags )                 { _whoFlags = whoFlags; }
    virtual unsigned long   whoFlags( void ) const                                    { return _whoFlags; }
    virtual void            who( const unsigned long& flag, const bool& value )       { whoFlags( value ? (whoFlags()|flag) : (whoFlags()&(~flag)) ); }
    virtual bool            who( const unsigned long& flag ) const                    { return ( ( whoFlags() & flag ) == flag ); }
    virtual void            pedit( Creature* pedit )                                  { _pedit = pedit; }
    virtual Creature*       pedit( void )                                             { return _pedit; }
    virtual void            aedit( Area* aedit )                                      { _aedit = aedit; }
    virtual Area*           aedit( void )                                             { return _aedit; }
    virtual void            oedit( Object* oedit )                                    { _oedit = oedit; }
    virtual Object*         oedit( void )                                             { return _oedit; }
    virtual void            medit( Mob* medit )                                       { _medit = medit; }
    virtual Mob*            medit( void )                                             { return _medit; }
    virtual void            sedit( SocialCommand* sedit )                             { _sedit = sedit; }
    virtual SocialCommand*  sedit( void )                                             { return _sedit; }
    virtual void            note( Note* note )                                        { _note = note; }
    virtual Note*           note( void ) const                                        { return _note; }
    virtual void            title( const std::string& title );
    virtual const char*     title( void ) const                                       { return _title.c_str(); }
    virtual void            poofin( const std::string& poofin )                       { _poofin = poofin; }
    virtual const char*     poofin( void ) const                                      { return _poofin.c_str(); }
    virtual void            poofout( const std::string& poofout )                     { _poofout = poofout; }
    virtual const char*     poofout( void ) const                                     { return _poofout.c_str(); }
    virtual void            board( const unsigned short& board )                      { _board = board; }
    virtual unsigned short  board( void ) const                                       { return _board; }
    void                    practices( const unsigned short& practices )              { _practices = practices; }
    unsigned short          practices( void ) const                                   { return _practices; }
    void                    trains( const unsigned short& trains )                    { _trains = trains; }
    unsigned short          trains( void ) const                                      { return _trains; }
    void                    gains( const unsigned short& gains )                      { _gains = gains; }
    unsigned short          gains( void ) const                                       { return _gains; }
    void                    age( const unsigned short& age )                          { _age = age; }
    unsigned short          age( void ) const                                         { return _age; }
    void                    points( const unsigned short& points )                    { _points = points; }
    unsigned short          points( void ) const                                      { return _points; }
    void                    gold( const unsigned& gold )                              { _gold = gold; }
    unsigned                gold( void ) const                                        { return _gold; }
    void                    silver( const unsigned& silver )                          { _silver = silver; }
    unsigned                silver( void ) const                                      { return _silver; }
    void                    bankGold( const unsigned long& bankGold )                 { _bankGold = bankGold; }
    unsigned long           bankGold( void ) const                                    { return _bankGold; }
    void                    bankSilver( const unsigned long& bankSilver )             { _bankSilver = bankSilver; }
    unsigned long           bankSilver( void ) const                                  { return _bankSilver; }

    // Avatar-specific public methods...
    void                    loadObjectContents( ObjContainer* container, const char* hash );
    bool                    hasInput( void );
    std::string             getInput( void );
    bool                    hasOutput( void );
    void                    flushOutput( void );
    bool                    checkPassword( const std::string& password );
    std::string             listWhoFlags( void );

    // Statics...
    static const char*      getWhoFlagName( const unsigned long& flag );
    static unsigned long    getWhoFlagType( const std::string& flag );

  private:
    // Low level/System members...
    Socket*                 _socket;
    ColorString             _output;
    unsigned short          _status;
    bool                    _disconnected;

    // Game-related members...
    Composing               _composing;
    unsigned long           _whoFlags;
    unsigned long           _adminFlags;
    char                    _gechoColor;
    std::string             _replyTo;
    unsigned long           _channelFlags;
    Creature*               _pedit;
    Area*                   _aedit;
    Object*                 _oedit;
    Mob*                    _medit;
    SocialCommand*          _sedit;
    Note*                   _note;
    std::string             _title;
    std::string             _poofin;
    std::string             _poofout;
    unsigned short          _practices;
    unsigned short          _trains;
    unsigned short          _gains;
    unsigned short          _age;
    unsigned short          _points;
    unsigned                _gold;
    unsigned                _silver;
    unsigned long           _bankGold;
    unsigned long           _bankSilver;
    unsigned short          _board;

    // Avatar-specific private methods...
    void                    processOutput( const std::string& text );
};



#endif // #ifndef H_SYMPHONY_AVATAR

